import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 导入动态路由
import departments from './modules/departments' // 组织架构
import employees from './modules/employees' // 员工
import setting from './modules/setting' // 公司设置
import salarys from './modules/salarys' // 工资
import social from './modules/social' // 社保
import attendances from './modules/attendances' // 考勤
import approvals from './modules/approvals' // 审批
import permission from './modules/permission' // 权限管理
import upload from './modules/upload' // 拖拽上传
/**
 * 动态路由
 */
export const asyncRoutes = [
  departments,
  employees,
  setting,
  salarys,
  social,
  attendances,
  approvals,
  permission,
  upload
]

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 * 静态路由
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true // 控制这个路由是否在左侧边上显示
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true // 控制这个路由是否在左侧边上显示
  }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes] // 动态路由与今天路由结合  数量不是固定的 需要筛选
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重新设置路由的可匹配路径
}

export default router
